package com.twu.biblioteca;

/**
 * Created with IntelliJ IDEA.
 * User: mbokhari
 * Date: 11/07/2013
 * Time: 13:20
 * To change this template use File | Settings | File Templates.
 */
public class Member {
    private LibraryNumberGenerator libNumGen;
    private String password;
    private long newLibNum;
    private boolean loggedIn = false;
    private Notifier notifier = new Notifier();


    public Member(LibraryNumberGenerator libNumGen, String password) {
        this.libNumGen = libNumGen;
        newLibNum = libNumGen.generateNewLibraryNumber();
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

    public void printLibraryNumber() {
        notifier.printMessage(getLibraryNumber());
    }

    public String getLibraryNumber() {
        return libNumGen.formatLibraryNumber(newLibNum);

    }

    public boolean memberLogIn(String password){
        if (this.password.equals(password)) {
            notifier.printMessage("You are now logged in.");
            return loggedIn = true;
        }
        else {
            notifier.printMessage("Log in has been unsuccessful. The library number/password entered is incorrect.");
        }
        return loggedIn;
    }

    public boolean checkIfLoggedIn() {
        return loggedIn;
    }
}
